using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DAL;
using BLL;
using DTO;

namespace WellmeadowsHospital
{
    public partial class frmAddWaitList : DevExpress.XtraEditors.XtraUserControl
    {
        AppointmentBLL appointmentBLL = new AppointmentBLL();
        WardBLL wardBLL = new WardBLL();
        PatientBLL patientBLL = new PatientBLL();
        ListWaitBLL listwaitBLL = new ListWaitBLL();
        public frmAddWaitList()
        {
            InitializeComponent();
            gcAppointListinAddWardListH.DataSource = appointmentBLL.SelectAll();
            gcWardListinAddWardListH.DataSource = wardBLL.SelectAllWard();
        }

        private void txtSearchAppontinAddWaitH_KeyPress(object sender, KeyPressEventArgs e)
        {
            string key = txtSearchAppontinAddWaitH.Text;
            if (!key.Equals(""))
            {
                gcAppointListinAddWardListH.DataSource = appointmentBLL.SearchwithStafforPatient(key);
            }
            else
            {
                gcAppointListinAddWardListH.DataSource = appointmentBLL.SelectAll();
            }
        }

        private void gridView8_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
            string patientid = gridView8.GetRowCellValue(gridView8.GetSelectedRows()[0], gcolPatientIDinAddWardListH).ToString();
            gcPatientinAddWardListH.DataSource = patientBLL.Search(patientid);
            txtAppointIDinAddWardListH.Text = gridView8.GetRowCellValue(gridView8.GetSelectedRows()[0], gcolAppointIDinAddWard).ToString();
      
        }

        private void gridView21_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
            txtWardIDinAddWardH.Text = gridView21.GetRowCellValue(gridView21.GetSelectedRows()[0], gcolWardIDinAddWardListH).ToString();
        
        }

        private void simpleButton10_Click(object sender, EventArgs e)
        {
            try
            {
                ListWaitDTO nhap = new ListWaitDTO();
                string appointid = txtAppointIDinAddWardListH.Text;
                nhap.AppointmentID = txtAppointIDinAddWardListH.Text;
                nhap.WardID = txtWardIDinAddWardH.Text;
                nhap.DateRegistered = dateRegisinAddWardH.DateTime;
                nhap.Status = cbbStatusinAddWardH.SelectedItem.ToString();
                if (listwaitBLL.Insert(nhap).Equals("success") && appointmentBLL.UpdateOnListWait(appointid).Equals("success"))
                {

                    MessageBox.Show("Insert ListWard success!");
                }
                else
                {
                    MessageBox.Show(listwaitBLL.Insert(nhap));
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
        }
    }
}
